﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using zichan.Entity;

namespace zichan.Common
{
    public class PowerHelp
    {
        public static bool Check(string controller, string action)
        {
            List<Menu> menus = GetUserMenu();
            return menus.Count(o => o.Controller == controller.ToLower() && o.Action == action.ToLower()) > 0;
        }

        public static List<Menu> GetUserMenu()
        {
            string sessionID = HttpContext.Current.Session.SessionID;
            var qxmenu = HttpContext.Current.Cache[sessionID + "zcqxmenu"];
            List<Menu> menus;
            if (qxmenu == null || (qxmenu as List<Menu>).Count() == 0)
            {
                string[] idname = HttpContext.Current.User.Identity.Name.Split(':');
                menus = zichan.BLL.MenuService.GetUserMenus(Convert.ToInt32(idname[0]));
                qxmenu = menus;
                HttpContext.Current.Cache[sessionID + "zcqxmenu"] = menus;
            }
            else
                menus = qxmenu as List<Menu>;
            return menus;

        }
    }
}